<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>CMS系统</title>

<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>

<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">


					<div class="clearfix"></div>



					<br />




				</div>
			</div>



			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left">
							<h3>卡密管理</h3>
						</div>


					</div>
					<div class="clearfix"></div>

					<div class="row">
						<div class="col-md-12 col-sm-12 col-xs-12">
							<div class="x_panel">
								<div class="x_title">
									<h2>卡密生成</h2>

									<div class="clearfix"></div>
								</div>
								<div class="x_content">

									<form class="form-horizontal form-label-left" novalidate>



										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">卡类型 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="type" onchange="show(this)">
													<option value="4" onclick="showType()">面值卡</option>
													<option value="5" onclick="showType() ">购物卡</option>
													<option value="1" onclick="hindType() ">月卡</option>
													<option value="2" onclick="hindType() ">季卡</option>
													<option value="3" onclick="hindType() ">年卡</option>
													<option value="6" onclick="hindType() ">等值卡</option>
													<option value="7" onclick="hindType() ">自定义卡</option>
													<option value="8" onclick="hindType() ">挪车卡</option>
												</select>
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">费率 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="feelroute">
													<c:forEach items="${freeroutes}" var="s" varStatus="z">
														<option value="${s.name}">${s.name}</option>
													</c:forEach>
												</select>
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">有效期 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="time"
													class="form-control col-md-7 col-xs-12" name="name"
													placeholder="充值前有效期，例如：${today}" required="required" >
											</div>
										</div>

										<div class="item form-group" id="money_box">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">面值 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="money" class="form-control col-md-7 col-xs-12"
													name="name" placeholder="例如：100" required="required"
													type="number">
											</div>
										</div>
										<div class="item form-group" id="shopmoney_box" style="display:none;">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name">购物面值 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="shopmoney" class="form-control col-md-7 col-xs-12"
													   name="name" placeholder="例如：100" required="required"
													   type="number">
											</div>
										</div>

										<div class="item form-group" id="probationperiod_box">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">充值有效期 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="probationperiod"
													class="form-control col-md-7 col-xs-12" name="name"
													placeholder="充值后有效期" required="required" type="number">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">开卡数量 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="nums" class="form-control col-md-7 col-xs-12"
													name="name" placeholder="例如：10000" required="required"
													type="number">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name" id=updateshop">充值更改商家<span
													class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="isupdateshop">
														<option value="1" selected="selected">允许</option>
														<option value="0">不允许</option>
												</select>
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">接收人<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="username" class="form-control col-md-7 col-xs-12"
													name="name" placeholder="" required="required">
											</div>
											<!--<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="parentid">
													<c:forEach items="${users}" var="s" varStatus="z">
														<c:if test="${s.username == null }">
															<option value="${s.id}">${s.mobile}</option>
														</c:if>
														<c:if test="${s.username != null }">
															<option value="${s.id}">${s.username}</option>
														</c:if>
													</c:forEach>
												</select>
											</div>  -->
										</div>

										<div class="ln_solid"></div>
										<div class="form-group">
											<div class="col-md-6 col-md-offset-3">
												<a type="submit" class="btn btn-primary"
													href="javascript:void(0)"
													onclick="history.back(-1);">取消</a>
												<a id="send"type="submit" class="btn btn-success" 
												onclick="ajaxPost()">开卡</a>
												
												
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<!-- /page content -->


		</div>
	</div>
	<script type="text/javascript">
		function show(obj){
			document.getElementById("shopmoney_box").style.display=(obj.value==7)?"":"none";
		}
	</script>
	<script type="text/javascript">
		//选项选中事件
		function hindType() {
			document.getElementById("money_box").style.display = "none"; //隐藏
			document.getElementById("probationperiod_box").style.display = "none"; //隐藏
		}
		function showType() {
			document.getElementById("money_box").style.display = ""; //显示
			document.getElementById("probationperiod_box").style.display = ""; //显示
		}
		// ajax 对象
		function ajaxObject() {
			var xmlHttp;
			try {
				// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				// Internet Explorer
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
						alert("您的浏览器不支持AJAX！");
						return false;
					}
				}
			}
			return xmlHttp;
		}
	
		// ajax post请求：
		function ajaxPost() {
			var time = $("#time").val();
			var money = $("#money").val();
			var shopmoney = $("#shopmoney").val();
			var probationperiod = $("#probationperiod").val();
			var nums = $("#nums").val();
			var type = $("#type").find("option:selected").val();
			var username = $("#username").val();
			var feelroute = $("#feelroute").find("option:selected").val();
            var isupdateshop = $("#isupdateshop").find("option:selected").val();
			var ajax = ajaxObject();
			ajax.open("post", "insertCardsNew?type=" + type + "&feelroute=" +
				feelroute + "&username=" +
				username + "&time=" +
				time + "&money=" +
				money + "&shopmoney=" +
				shopmoney +"&probationperiod=" +
				probationperiod + "&nums=" +
				nums + "&isupdateshop=" +
                isupdateshop, true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							location.href = "content_chongzhikaguanli";
							alert("开卡成功，请在充值卡管理页面查看");
						} else {
							//创建失败
							location.href = "selectChongzhika?curPage="
									+ 1 +"&batch=" + result;
							alert("开卡成功，请在充值卡管理页面查看,批次号：" + result);
						}
					} else {
						//请求失败
						alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
					}
				} else {
				}
			};
			ajax.send();
		}
	</script>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>

	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>

</body>
</html>